class RecentsController < ApplicationController
  # GET /recents
  # GET /recents.xml
  
  def index
    @recents = Recent.find(:all)
    
    respond_to do |format|
      format.html # index.rhtml
      format.xhtml { render :template => 'recents/index.rxhtml' }
      format.xml  { render :xml => @recents.to_xml }
    end
  end
  
  # GET /recents/1
  # GET /recents/1.xml
  def show
    @recent = Recent.find(params[:id])
    
    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @recent.to_xml }
    end
  end
  
  # GET /recents/new
  def new
    @recent = Recent.new
    
    respond_to do |format|
      format.html # new.rhtml
      format.xhtml { render :template => 'recents/new.rxhtml', :layout=>false }
      format.xml  { render :xml => @artifacts.to_xml }
    end
  end
  
  # GET /recents/1;edit
  def edit
    @recent = Recent.find(params[:id])
  end
  
  # POST /recents
  # POST /recents.xml
  def create
    @recent = Recent.new(params[:recent])
    
    respond_to do |format|
      if @recent.save
        flash[:notice] = 'Recent was successfully created.'
        format.html { redirect_to recent_url(@recent) }
        format.xml  { head :created, :location => recent_url(@recent) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @recent.errors.to_xml }
      end
    end
  end
  
  # PUT /recents/1
  # PUT /recents/1.xml
  def update
    @recent = Recent.find(params[:id])
    
    respond_to do |format|
      if @recent.update_attributes(params[:recent])
        flash[:notice] = 'Recent was successfully updated.'
        format.html { redirect_to recent_url(@recent) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @recent.errors.to_xml }
      end
    end
  end
  
  # DELETE /recents/1
  # DELETE /recents/1.xml
  def destroy
    @recent = Recent.find(params[:id])
    @recent.destroy
    
    if request.xhr?
      @artifacts = Artifact.get_artifacts(@session_user, @context_elements)
      render :action => 'update_panes', :type=>'rjs' and return true 
    end    
    
    respond_to do |format|
      format.html { redirect_to recents_url }
      format.xml  { head :ok }
    end

  end
end

